#ifndef _INCLUDE_PROCESS_H_
#define _INCLUDE_PROCESS_H_

#include "stdint.h"
#include "thread.h"

#define default_prio 31 // default priority of process to execute
#define USER_STACK3_VADDR                                                      \
  (0xc0000000 - 0x1000) // 定义了一页C语言程序的栈顶起始地址（虚拟）,书p511
#define USER_VADDR_START                                                       \
  0x8048000 // linux下大部分可执行程序的入口地址（虚拟）都是这个附近，我们也仿照这个设定

/**
 * @brief create a process
 *
 * @param filename Name of the user process, also used as the filename. (In the
 * primary version, a function should be placed in this parameter)
 * @param thread_name The name of the thread
 */
void process_execute(void* filename, char* thread_name);

/**
 * @brief initialize the user virtual address bitmap
 *
 * @param user_prog the PCB of the user process
 */
void create_user_vaddr_bitmap(struct task_struct* user_prog);

/**
 * @brief Initializes the user Page Directory Entry (PDE).
 *
 * @return The virtual address of the page directory entry.
 */
uint32_t* init_user_page_dir_entry();

/**
 * @brief Initializes the context of a user process.
 * @details This function sets up the stack and other necessary information to
 * execute a given function in user mode.
 *
 * @param filename_ Pointer to the function to be executed as the user process.
 */
void start_process(void* filename_);

/**
 * @brief Activate the page directory for a specified task to prevent page
 * faults caused by switching between threads and processes.
 *
 * @param p_thread Pointer to the task structure
 */
void pg_dir_entry_activate(struct task_struct* p_thread);

/**
 * @brief Activate process-specific page directory and update privilege level 0
 * stack pointer (esp0) in TSS
 *
 * @param p_thread Pointer to the task structure of the process/thread
 */
void process_activate(struct task_struct* p_thread);

#endif // !_INCLUDE_PROCESS_H_
